#include"List.h"

SLD* Openmem(x)
{
	//assert(pphead);
	SLD* cut = (SLD*)malloc(sizeof(SLD));
	assert(cut);
	cut->num = x;
	cut->next = NULL;
	cut->prev = NULL;
	return cut;
}
void SLinit(SLD** pphead)
{
	assert(pphead);
	SLD* cut = Openmem(-1);
	*pphead = cut;
	cut->next = *pphead;
	cut->prev = *pphead;
	cut->num = 0;
}
void SLPushBack(SLD* phead, classnode x)
{
	SLD* cut = Openmem(x);
	SLD* head = phead->prev;
	phead->prev = cut;
	cut->next = phead;
	cut->prev = head;
	head->next = cut;

}
void SLprint(SLD* phead)
{
	SLD* cut = phead;
	printf("head->");
	if (phead == NULL)
	{
		return;
	}
	while (cut->next != phead)
	{
		printf("%d->", cut->next->num);
		cut = cut->next;
	}
	printf("head");
}
void SLPushFront(SLD* phead, classnode x)
{
	assert(phead);
	SLD* cut = phead->next;
	SLD* newnode = Openmem(x);
	newnode->next = cut;
	cut->prev = newnode;
	newnode->prev = phead;
	phead->next = newnode;
}
void SLPopFront(SLD* phead)
{
	if (phead == phead->next)
	{
		assert(phead);
	}
	SLD* cut = phead->next;
	SLD* cutnext = cut->next;
	cutnext->prev = phead;
	phead->next = cutnext;
	free(cut);
	cut = NULL;
}

void SLPopBack(SLD* phead)
{
	if (phead == phead->prev)
	{
		assert(phead);
	}
	SLD* cut = phead->prev;
	SLD* cutprev = cut->prev;
	cutprev->next = phead;
	phead->prev = cutprev;
	free(cut);
	//cut = NULL;
}